import request from './request'
import type { Product, ApiResponse, PaginationParams, FilterParams } from '@/types'

/**
 * 获取产品列表
 */
export function getProductList(params?: PaginationParams & FilterParams) {
  return request<ApiResponse<Product>>({
    url: '/products/',
    method: 'get',
    params
  })
}

/**
 * 获取产品详情
 */
export function getProduct(id: number) {
  return request<Product>({
    url: `/products/${id}/`,
    method: 'get'
  })
}

/**
 * 创建产品
 */
export function createProduct(data: Partial<Product>) {
  return request<Product>({
    url: '/products/',
    method: 'post',
    data
  })
}

/**
 * 更新产品
 */
export function updateProduct(id: number, data: Partial<Product>) {
  return request<Product>({
    url: `/products/${id}/`,
    method: 'put',
    data
  })
}

/**
 * 删除产品
 */
export function deleteProduct(id: number) {
  return request({
    url: `/products/${id}/`,
    method: 'delete'
  })
}

/**
 * 切换产品激活状态
 */
export function toggleProductActive(id: number) {
  return request<Product>({
    url: `/products/${id}/toggle_active/`,
    method: 'post'
  })
}

/**
 * 批量删除产品
 */
export function bulkDeleteProducts(ids: number[]) {
  return request({
    url: '/products/bulk_delete/',
    method: 'post',
    data: { ids }
  })
}

